<template>

	<view class="stepper fboxRow Ycenter Xcenter">
		<view class="minus fboxRow Ycenter Xcenter font22 bksCIcon bks-c-jianhao"
			:class="info.subjectScore <= 0 ? 'active' : ''" @tap="minus"></view>
		<input class="weui-input" maxlength="5" :data-max="info.max" :data-name="info.subjectName"
			:data-id="info.id" :value="info.subjectScore" @blur="bindMax" @input="bindKeyInput" placeholder="0" />
		<view class="plus fboxRow Ycenter Xcenter font22 bksCIcon bks-c-ziyuan119tianjia"
			:class="info.subjectScore >= info.max ? 'active' : ''" @tap="plus"></view>
	</view>
</template>

<script>
	import {
		myScoreUpdate,
		scoreEntering,
		isAnalysis
	} from '@/api/bks.volunteer.js'
	import {
		getBksInfo
	} from '@/static/js/bks.common.js'
	export default {
		props: {
			info: {
				type: Object,
				default: () => {
					return {
						// "scoreInfos": [],
						// examName: '三诊成绩',
						// time: '2021.04.28 14:30:20'
					}
				}
			}
		},
		components: {},
		data() {
			return {}
		},
		methods: {
			bindKeyInput: function(e) {
				const { subjectName } = this.info
				var reg = new RegExp(/^\d{1,3}(\.5)?$/);
				if (reg.test(e.detail.value)) {
					this.$emit('change', {
						name: subjectName,
						value: e.detail.value
					})
				}
			},
			minus() {
				const {
					subjectScore
				} = this.info
				this.max(subjectScore - 1)
			},
			plus() {
				const {
					subjectScore,
					max
				} = this.info
				if (subjectScore < max) {
					this.max(subjectScore + 1)
				}
			},
			max(num) {
				const {
					max,
					subjectName
				} = this.info
				let curNum = num
				if (num > max) {
					curNum = max
				}
				if (num <= 0) {
					curNum = 0
				}
				this.$emit('change', {
					name: subjectName,
					value: curNum
				})
			},
			bindMax() {
				const {
					subjectScore,
					max,
					subjectName
				} = this.info
				let curNum = subjectScore
				if (subjectScore > max) {
					curNum = max
				}
				if (subjectScore <= 0) {
					curNum = 0
				}
				this.$emit('change', {
					name: subjectName,
					value: curNum
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.weui-input {
		width: 100rpx;
		text-align: center;
		font-size: 26rpx;
	}

	.minus,
	.plus {
		width: 44rpx;
		height: 44rpx;
	}

	.active {
		color: #c8c9cc
	}
</style>